package srvbiz

import (
	"cloud_worm/util/proto/ujson"
	"cloud_worm/access/server/client"
	"fmt"
	"github.com/golang/glog"
	"cloud_worm/util/proto/uweapon"
)

type MsgCmd struct {
}

func (c *MsgCmd) Deal(agent *client.Agent, data []byte) {
	var msg ujson.MsgCmd
	if err := msg.UnmarshalJSON(data); err != nil {
		glog.Errorf("cmd msg Unmarshal failed: %s", err.Error())
		return
	}

	cmdRet := uweapon.CmdBrief{
		TaskId: msg.TaskId,
		Input: fmt.Sprintf("%s %s", msg.Cmd, msg.Params),
		Result: msg.Result,
		Status: msg.Status,
	}

	// 将cmd task result写入到chan中
	agent.CmdChanLock.Lock()
	if ch, exist := agent.CmdChanMap[cmdRet.TaskId]; exist {
		ch <- cmdRet
	}
	agent.CmdChanLock.Unlock()

	return
}
